<link href="__PUBLICURL__/ztree/css/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script src="__PUBLICURL__/ztree/jquery.ztree.js"></script>
<script src="__PUBLICURL__/ztree/jquery.ztree.exhide.js"></script>
<script src="__PUBLICURL__/ztree/jquery.ztree.excheck.js"></script>
<script>
var zTree;
var setting = {
    view: {
		nameIsHTML: true
    },
	check: {
            enable: true
    },
    data: {
		key: {
			title:"title"
		},
		
        simpleData: {
            enable: true,
            idKey: "cid",
            pIdKey: "pid",
            rootPId: ""
        }
    }
};
var zNodes = [
 <?php echo $class_tree; ?>
];
$(document).ready(function() {
    var t = $("#tree");
    t = $.fn.zTree.init(t, setting, zNodes);
});
</script>
<style type="text/css">
.form-group table { table-layout: fixed;  }
.form-group table tr {}
.form-group table td { padding:10px; background-image:url("/public/images/table_bg.jpg"); background-repeat:repeat-x; background-position:bottom left; height:25px;}
.form-group tr:hover { background-color:#fafafa}
.source {padding: 10px;border: 1px solid #ddd;margin-bottom: 10px;}
</style>
<div class="dux-tools">
  <div class="bread-head">管理组管理 <span class="small">管理员分组管理</span> </div>
  <br>
  <div class="tools-function clearfix">
    <div class="float-left"> <a class="button button-small bg-main icon-list" href="__URL__"> 管理组列表</a> </div>
    <?php if(model('user_group')->model_power('user','add')){ ?>
    <div class="button-group float-right"> <a class="button button-small bg-dot icon-plus dropdown-toggle"> 添加管理组 <span class="downward"></span></a>
      <ul class="drop-menu pull-right">
        <li><a href="__URL__/add">添加管理组</a></li>
      </ul>
    </div>
    <?php } ?>
  </div>
</div>
<div class="admin-main">
  <form action="__URL__/{$action}_save/time-<?php echo time() ?>-ajax-true" class="form-x dux-form form-auto" id="form" name="form" method="post">
    <div class="tab dux-tab">
      <div class="panel dux-box  active">
        <div class="panel-head">
          <div class="tab-head"> <strong>管理员组设置</strong>
            <ul class="tab-nav">
              <li class="active"><a href="#tab-1">基本信息</a> </li>
              <li><a href="#tab-2">栏目内容权限</a> </li>
              <li><a href="#tab-3">功能权限</a> </li>
            </ul>
          </div>
        </div>
        <div class="tab-body">
          <div class="tab-panel active" id="tab-1">
            <div class="form-group">
              <div class="label">
                <label>管理组名称</label>
              </div>
              <div class="field">
                <input name="name" type="text" class="input" id="name" value="{$info.name}" reg="\S" msg="管理组名称不能为空" />
                <div class="input-note"><!--if:{$info['keep']==1}-->保留用户组不受权限控制<!--{/if}--></div>
              </div>
            </div>
            <!--if:{$user['grade']==1}-->
            <div class="form-group">
              <div class="label">
                <label>管理等级</label>
              </div>
              <div class="field">
                <select name="grade" id="grade" class="input">
                  <option value="1" <!--if:{$info['grade']==1}--> selected="selected" <!--{/if}--> >一级管理组
                  </option>
                  <option value="2" <!--if:{$info['grade']==2}--> selected="selected" <!--{/if}--> >二级管理组
                  </option>
                  <option value="3" <!--if:{$info['grade']==3}--> selected="selected" <!--{/if}--> >三级管理组
                  </option>
                </select>
                <div class="input-note">低级别将看不到高级别的管理组与所属用户(只有级别等于一级的用户才可设置级别，默认三级用户)</div>
              </div>
            </div>
            <!--{/if}--> 
          </div>
          <div class="tab-panel" id="tab-2">
            <div class="form-group">
              <div class="label">
                <label>内容访问权限</label>
              </div>
              <div class="field">
                <ul id="tree" class="ztree">
                </ul>
              </div>
            </div>
          </div>
          <div class="tab-panel" id="tab-3">
            <div class="form-group">
               <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="150" align="right">主菜单访问权限</td>
                    <td colspan="2"><fieldset class="source">
                        <legend>选择权限</legend>
                        <!--foreach:{$menu_list $vo}--> 
                        <input name="menu_power[]" id="menu_power_{$vo['id']}" type="checkbox" value="{$vo['id']}"  <!--if:{!empty($menu_power)&&in_array($vo['id'],$menu_power)}--> checked="checked" <!--{/if}--> /> <label for="menu_power_{$vo['id']}">{$vo.name}</label>&nbsp;&nbsp; 
                        <!--{/foreach}-->
                      </fieldset></td>
                  </tr>
                  <!--foreach:{$menu_list $vo}-->
                  <tr>
                    <td width="150" align="right">{$vo.name}操作权限</td>
                    <td colspan="2"><?php $list=model('menu')->menu_list($vo['id']); if(!empty($list)) foreach($list as $vo){?>
                      <fieldset class="source">
                        <legend><input class="sub" id="model_power_{$vo['id']}" name="model_power[{$vo['id']}][]" type="checkbox" value="{$vo['id']}" <!--if:{!empty($model_power)&&in_array($vo['id'],(array)$model_power[$vo['id']])}--> checked="checked" <!--{/if}--> > <label for="model_power{$vo['id']}">{$vo.name}</label></legend>
                        <?php $list=model('user_group')->admin_power($vo['id']); if(!empty($list)) foreach($list as $val){?>
                        <input class="sub" name="model_power[{$vo['id']}][]" type="checkbox" value="{$val['action']}"  <!--if:{!empty($model_power)&&in_array($val['action'],(array)$model_power[$vo['id']])}--> checked="checked" <!--{/if}--> /> {$val.name}&nbsp;&nbsp;
                        <?php } ?>
                      </fieldset>
                      <?php } ?></td>
                  </tr>
                  <!--{/foreach}-->
                  <tr>
                    <td width="150" align="right">表单管理权限</td>
                    <td colspan="2"><!--foreach:{$form_list $vo}-->
                      
                      <fieldset class="source">
                        <legend><input class="sub" id="form_power_{$vo['id']}" name="form_power[{$vo['id']}][]" type="checkbox" value="{$vo['id']}" <!--if:{!empty($form_power)&&in_array($vo['id'],(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}--> > <label for="form_power_{$vo['id']}">{$vo.name}</label></legend>
                        <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="visit"  <!--if:{!empty($form_power)&&in_array('visit',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}--> /> 浏览&nbsp;&nbsp; <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="add"  <!--if:{!empty($form_power)&&in_array('add',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}--> /> 添加&nbsp;&nbsp; <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="edit"  <!--if:{!empty($form_power)&&in_array('edit',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}--> /> 编辑&nbsp;&nbsp; <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="del"  <!--if:{!empty($form_power)&&in_array('del',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}--> /> 删除&nbsp;&nbsp;
                      </fieldset>
                      
                      <!--{/foreach}--></td>
                  </tr>
                </table>

            </div>
          </div>
        </div>
        <?php if(model('user_group')->model_power('user_group','add')||model('user_group')->model_power('user_group','edit')){ ?>
        <div class="panel-foot">
          <div class="form-button">
            <div id="tips"></div>
            <input name="id" type="hidden" value="{$info.id}" />
            <input name="class_power" id="class_power" type="hidden" value="" />
            <button class="button bg-main" type="submit">保存</button>
          </div>
        </div>
       <?php } ?> 
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
//tab菜单
$("#tab").idTabs();
$('.source input').click(function() {
	var num=0;
	$(this).parent().find(".sub").each(function(){
		if($(this).attr("checked")){
			num=num+1;
    	}
    })
	if(num>0){
		$(this).parent().find("legend input").removeAttr('checked');
	}
});
//提交表单
savelistform({addurl:"__URL__/add",listurl:"__URL__",
data:function(){
	var zTree = $.fn.zTree.getZTreeObj("tree");
	var nodes = zTree.getCheckedNodes(true);
	var purview = "";
	for (var i = 0; i < nodes.length; i++) {
    	purview +=  nodes[i].cid+",";
    }
	$('#class_power').val(purview);
}
});
</script>